/*
 * Copyright (c) 2011 Nathan Byrd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package org.stackconfig.web.gwt.client.activities;

import com.allen_sauer.gwt.dnd.client.PickupDragController;
import com.allen_sauer.gwt.dnd.client.drop.AbsolutePositionDropController;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.SimplePanel;
import org.stackconfig.web.gwt.client.widgets.Component;
import org.stackconfig.web.gwt.client.widgets.ComponentPanel;
import org.stackconfig.web.gwt.client.widgets.DraggableWrapperWidget;


/**
 * Sample activity
 */
public class DesignActivity extends EmptyActivity {
    interface DesignActivityUiBinder extends UiBinder<AbsolutePanel, DesignActivity> {

    }

    private static DesignActivityUiBinder uiBinder = GWT.create(DesignActivityUiBinder.class);
    @UiField
    SimplePanel transformSection;


    @Override
    public void start(AcceptsOneWidget containerWidget, EventBus eventBus) {
        AbsolutePanel mainPanel = uiBinder.createAndBindUi(this);
        containerWidget.setWidget(mainPanel);

        PickupDragController dragController = new PickupDragController(mainPanel, false);
        dragController.setBehaviorMultipleSelection(false);
        dragController.setBehaviorDragProxy(false);
        dragController.setBehaviorConstrainedToBoundaryPanel(true);

        // Default drop
        dragController.registerDropController(new AbsolutePositionDropController(mainPanel));

        ComponentPanel transformPanel = new ComponentPanel(dragController);
        Component testComponent = new Component(dragController);
        transformPanel.add(new DraggableWrapperWidget(testComponent));
        transformSection.add(transformPanel);

    }
}
